#!/bin/bash

echo "Executing script by: HUANGXIAOLEI 24055060326"

echo "-----------------------------------------"

SOURCE_FILE="scores.txt"

OUTPUT_DIR="students"

if [ ! -f "$SOURCE_FILE" ]; then

    echo "Error: Source file '$SOURCE_FILE' not found!"

    exit 1

fi


mkdir -p "$OUTPUT_DIR"



while read name gender id java_subj java_score python_subj python_score cpp_subj cpp_score linux_subj linux_score; do

    

    total=$(( java_score + python_score + cpp_score + linux_score ))

    

    average=$(echo "scale=1; $total / 4" | bc)

    

    output_file="$OUTPUT_DIR/$name.txt"

    

    {

        echo "name: $name"

        echo "id: $id"

        echo "gender: $gender"

        echo "scores: $java_subj $java_score $python_subj $python_score $cpp_subj $cpp_score $linux_subj $linux_score"

        echo "total: $total"

        echo "average: $average"

    } > "$output_file"

    

    echo "Created file: $output_file"



done < "$SOURCE_FILE"
echo "-----------------------------------------"
echo "All student files have been created in the '$OUTPUT_DIR' directory."
exit 0
